package com.cqcetbbs.smartlab.cqcetbbs.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cqcetbbs.smartlab.cqcetbbs.R;
import com.cqcetbbs.smartlab.cqcetbbs.javabean.ReplyInfos;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

/**
 * Created by user on 2017/10/5.
 */

public class CommentAdapter extends BaseAdapter {

    Context context;
    ArrayList<ReplyInfos.ReplyInfo> list;

    public CommentAdapter(Context context, ArrayList<ReplyInfos.ReplyInfo> list) {
        this.context = context;
        this.list = list;

    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {

        ViewHolder viewHolder = null;
        if (view == null) {
            viewHolder = new ViewHolder();
            view = View.inflate(context, R.layout.comment_list_item, null);
            viewHolder.head_icon = view.findViewById(R.id.head_icon);
            viewHolder.user_name = view.findViewById(R.id.user_name);
            viewHolder.replyandreply = view.findViewById(R.id.replyandreply);
            viewHolder.tv_comment = view.findViewById(R.id.tv_comment);
            viewHolder.tv_time = view.findViewById(R.id.tv_time);
            //  viewHolder.btn_delete = view.findViewById(R.id.btn_delete);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.head_icon.setImageResource(R.drawable.head_icon);
        viewHolder.user_name.setText("用户名");
        SimpleDateFormat format = new SimpleDateFormat("M-d HH:mm:ss");
        String time = format.format(new Date());
        viewHolder.tv_time.setText(time);
        if (list == null) {
            viewHolder.tv_comment.setText("");
        } else {

            viewHolder.tv_comment.setText(list.get(i).getReply_content());
        }
//        viewHolder.btn_delete.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                if (onDeletedLisenter != null) {
//                    onDeletedLisenter.onDeleted();
//                }
//            }
//        });

        viewHolder.replyandreply.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if(onReplyAndReplyLisenter!=null){
                    onReplyAndReplyLisenter.ReplyAndReply();
                }
            }
        });
        return view;
    }

    public static class ViewHolder {
        ImageView head_icon;
        ImageView replyandreply;
        TextView user_name;
        TextView tv_comment;
        TextView tv_time;
        TextView btn_delete;
    }

    onDeletedLisenter onDeletedLisenter;

    public interface onDeletedLisenter {
        void onDeleted();
    }

    public void setonDeletedLisenter(onDeletedLisenter onDeletedLisenter) {
        this.onDeletedLisenter = onDeletedLisenter;
    }


    onReplyAndReplyLisenter onReplyAndReplyLisenter;

    public interface onReplyAndReplyLisenter {
        void ReplyAndReply();
    }
    public void onReplyAndReplyLisenter(onReplyAndReplyLisenter onReplyAndReplyLisenter) {
        this.onReplyAndReplyLisenter = onReplyAndReplyLisenter;
    }


}